package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.uuid.UUID;
import com.ruoyi.system.domain.BieAccessCard;
import com.ruoyi.system.domain.BieHouse;
import com.ruoyi.system.domain.BieHouseholder;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.BieBlacklistMapper;
import com.ruoyi.system.domain.BieBlacklist;
import com.ruoyi.system.service.IBieBlacklistService;

/**
 * 黑名单记录Service业务层处理
 * 
 * @author zxl
 * @date 2021-05-03
 */
@Service
public class BieBlacklistServiceImpl implements IBieBlacklistService 
{
    @Autowired
    private BieBlacklistMapper bieBlacklistMapper;

    @Autowired
    private BieHouseholderServiceImpl householderService;

    @Autowired
    private BieHouseServiceImpl houseService;

    @Autowired
    private BieAccessCardServiceImpl bieAccessCardService;
    /**
     * 查询黑名单记录
     * 
     * @param blacklistId 黑名单记录ID
     * @return 黑名单记录
     */
    @Override
    public BieBlacklist selectBieBlacklistById(String blacklistId)
    {
        return bieBlacklistMapper.selectBieBlacklistById(blacklistId);
    }

    /**
     * 查询黑名单记录列表
     * 
     * @param bieBlacklist 黑名单记录
     * @return 黑名单记录
     */
    @Override
    public List<BieBlacklist> selectBieBlacklistList(BieBlacklist bieBlacklist)
    {
        return bieBlacklistMapper.selectBieBlacklistList(bieBlacklist);
    }

    /**
     * 新增黑名单记录
     * 
     * @param bieBlacklist 黑名单记录
     * @return 结果
     */
    @Override
    public int insertBieBlacklist(BieBlacklist bieBlacklist)
    {
        //获取门禁卡表信息
        BieAccessCard bieAccessCard = bieAccessCardService.selectBieAccessCardById(bieBlacklist.getAccessCardId());

        //住户信息
        String holderId = bieAccessCard.getHolderId();
        BieHouseholder householder = householderService.selectBieHouseholderById(holderId);
        BeanUtils.copyProperties(householder,bieBlacklist);
        BeanUtils.copyProperties(bieAccessCard,bieBlacklist);

        //房子信息
        String houseId = bieAccessCard.getHouseId();
        BieHouse bieHouse = houseService.selectBieHouseById(houseId);
        BeanUtils.copyProperties(bieHouse,bieBlacklist);

        bieBlacklist.setBlacklistId(UUID.fastUUID().toString());
        bieBlacklist.setCreateTime(DateUtils.getNowDate());

        //System.out.println(bieBlacklist);
        //默认理由
        bieBlacklist.setRemarks("无");
        return bieBlacklistMapper.insertBieBlacklist(bieBlacklist);
    }

    /**
     * 修改黑名单记录
     * 
     * @param bieBlacklist 黑名单记录
     * @return 结果
     */
    @Override
    public int updateBieBlacklist(BieBlacklist bieBlacklist)
    {
        return bieBlacklistMapper.updateBieBlacklist(bieBlacklist);
    }

    /**
     * 批量删除黑名单记录
     * 
     * @param blacklistIds 需要删除的黑名单记录ID
     * @return 结果
     */
    @Override
    public int deleteBieBlacklistByIds(String[] blacklistIds)
    {
        return bieBlacklistMapper.deleteBieBlacklistByIds(blacklistIds);
    }

    /**
     * 删除黑名单记录信息
     * 
     * @param blacklistId 黑名单记录ID
     * @return 结果
     */
    @Override
    public int deleteBieBlacklistById(String blacklistId)
    {
        return bieBlacklistMapper.deleteBieBlacklistById(blacklistId);
    }
}
